﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminFunction.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BitPortal.Admin.Service.Work.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">

        var stateFn = function (value) {
            var returnValue = "";
            switch (value) {
                case 1: returnValue = "Đã khởi tạo";
                    break;
                case 2: returnValue = "Đã phân công";
                    break;
                case 3: returnValue = "Đang thực hiện";
                    break;
                case 4: returnValue = "Nhân viên xác nhận xong";
                    break;
                case 5: returnValue = "Khách hàng xác nhận xong";
                    break;
                case 6: returnValue = "Quản trị xác nhận xong, hoàn tất";
                    break;
                
            }
            return returnValue;
        };

        var priorityFn = function (value) {
            var returnValue = "";
            switch (value) {
                case 1: returnValue = "Ưu tiên cao";
                    break;
                case 2: returnValue = "Ưu tiên trung bình";
                    break;
                case 3: returnValue = "Ưu tiên thấp";
                    break;
            }
            return returnValue;
        };


        var LoadAttachs = function (value) {
            var template = "";
            var arr = value.split("#");
            for (var i = 0; i < arr.length; i++) {
                if (arr[i].length > 0) {
                    var name = arr[i].substring(arr[i].lastIndexOf('/') + 1);
                    template += '<a class="attachlink" href="' + arr[i] + '" target="_blank" title="' + name + '" ><img src="/Images/rar_32.png" width="16" alt="' + name + '" />' + name + '</a><br/>';
                }
            }
            return template;
        };
    </script>
</asp:Content>
<asp:Content ID="conten3" ContentPlaceHolderID="TopBarHolder" runat="Server">
    <ext:Toolbar ID="Toolbar1" runat="server">
        <Items>
            <%--<ext:Button runat="server" ID="btnAdd" Text="Thêm công việc" Icon="PageAdd" Scale="Medium"
                CausesValidation="false">
                <DirectEvents>
                    <Click OnEvent="btnAdd_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>--%>
            <ext:ToolbarSeparator />
            <ext:Button runat="server" ID="btnEdit" Text="Sửa công việc" Icon="Pencil" Scale="Medium"
                CausesValidation="false">
                <DirectEvents>
                    <Click OnEvent="btnEdit_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="200" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:ToolbarSeparator />
            
            <ext:SplitButton runat="server" ID="btnUpdate" Text="Cập nhật" Icon="PageEdit" Scale="Medium">
                <Menu>
                    <ext:Menu ID="Menu1" runat="server">
                        <Items>
                            <ext:MenuItem ID="MenuItem2" runat="Server" Text="Thay đổi trạng thái" Icon="CupEdit">
                                <Listeners>
                                    <Click Handler="#{Window4}.show();" />
                                </Listeners>
                            </ext:MenuItem>
                            
                        </Items>
                    </ext:Menu>
                </Menu>
                
            </ext:SplitButton>
            
            <ext:Button runat="server" ID="btnDelete" Text="Xóa công việc" Icon="PageDelete" Scale="Medium">
                <DirectEvents>
                    <Click OnEvent="btnDelete_Click">
                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:ToolbarSeparator />
            <ext:SplitButton runat="server" ID="btnTrash" Text="Thùng rác" Icon="Bin" Scale="Medium">
                <Menu>
                    <ext:Menu ID="Menu2" runat="server">
                        <Items>
                            <ext:MenuItem ID="MenuItem8" runat="server" Text="Xóa tất cả" Icon="Cancel">
                                <DirectEvents>
                                    <Click OnEvent="btnTrashEmpty_Click">
                                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                                    </Click>
                                </DirectEvents>
                            </ext:MenuItem>
                            <ext:MenuItem ID="MenuItem9" runat="server" Text="Xóa những bài được chọn" Icon="BinEmpty">
                                <DirectEvents>
                                    <Click OnEvent="btnTrashDelete_Click">
                                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                                    </Click>
                                </DirectEvents>
                            </ext:MenuItem>
                            <ext:MenuItem ID="MenuItem10" runat="server" Text="Bỏ khỏi thùng rác" Icon="ArrowTurnLeft">
                                <DirectEvents>
                                    <Click OnEvent="btnUnDelete_Click">
                                        <EventMask ShowMask="true" Msg="Waiting..." MinDelay="500" />
                                    </Click>
                                </DirectEvents>
                            </ext:MenuItem>
                        </Items>
                    </ext:Menu>
                </Menu>
                
            </ext:SplitButton>
        </Items>
    </ext:Toolbar>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <ext:Store ID="Store1" runat="server" OnRefreshData="Store1_RefreshData" RemoteSort="true" RemotePaging="true">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="WorkWarrantyID">
                <Fields>
                    <ext:RecordField Name="WorkWarrantyID" Type="Int" />
                    <ext:RecordField Name="UserId" Type="Int" />
                    <ext:RecordField Name="ErrorID" Type="Int" />

                    <ext:RecordField Name="WorkName" Type="String" />
                    <ext:RecordField Name="DescOfManager" Type="String" />
                    <ext:RecordField Name="DescOfEmployee" Type="String" />
                    <ext:RecordField Name="IsDescSure" Type="Boolean" />
					<ext:RecordField Name="StateWork" Type="Int" />
					<ext:RecordField Name="Expense" Type="Float" />
					
					<ext:RecordField Name="DateReport" Type="Date" />
					<ext:RecordField Name="DateManagerConfirm" Type="Date" />
					<ext:RecordField Name="DateFixed" Type="Date" />
					<ext:RecordField Name="DateCustomerConfirm" Type="Date" />
					<ext:RecordField Name="DateFinished" Type="Date" />
					<ext:RecordField Name="DateRequired" Type="Date" />

					<ext:RecordField Name="Priority" Type="Int" />
					<ext:RecordField Name="Comment" Type="String" />
					<ext:RecordField Name="UsersRepair" Type="String" />

                    <ext:RecordField Name="IsDeleted" Type="Boolean" />
                    <ext:RecordField Name="NoteGroupId" Type="Int" />

					<ext:RecordField Name="ErrorReport_ErrorName" ServerMapping="ErrorReport.ErrorName" Type="String" />
                    <ext:RecordField Name="ErrorReport_DesOfCustomer" ServerMapping="ErrorReport.DesOfCustomer" Type="String" />
                    <ext:RecordField Name="ErrorReport_DateReport" ServerMapping="ErrorReport.DateReport" Type="Date"  />
                    <ext:RecordField Name="ErrorReport_FilePath" ServerMapping="ErrorReport.FilePath" Type="String" />
					
                    </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="10" Mode="Raw" />
            <ext:Parameter Name="sort" Value="" />
            <ext:Parameter Name="dir" Value="" />
        </BaseParams>

        <SortInfo Field="WorkWarrantyID" Direction="DESC" />
    </ext:Store>

    <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true" Title="Danh sách lỗi"
        Height="600" RowHeight="1.0" StoreID="Store1">
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:ImageCommandColumn Header="" Align="Center" Width="60" Resizable="false">
                    <Commands>
                        <ext:ImageCommand CommandName="Notes" Icon="Note" ToolTip-Text="Xem ghi chú" Text="Ghi chú">
                        </ext:ImageCommand>
                        <ext:ImageCommand CommandName="Errors" Icon="Error" ToolTip-Text="Xem các lỗi khác cùng sản phẩm" Text="Lỗi ">
                        </ext:ImageCommand>
                    </Commands>
                </ext:ImageCommandColumn>
                <ext:Column Header="Mã công việc " DataIndex="WorkWarrantyID"  />            
                <ext:Column Header="Tên công việc" DataIndex="WorkName" />
                <%--<ext:Column Header="Đoán lỗi" DataIndex="DescOfManager" Groupable="true" />
                <ext:Column Header="Đoán lỗi" DataIndex="DescOfEmployee" Groupable="true" />--%>

                <ext:Column Header="Trạng thái" DataIndex="StateWork" Align="Center" Groupable="true" >
                    <Renderer Fn="stateFn" />
                </ext:Column>

                <ext:DateColumn Header="Ngày tạo" DataIndex="DateManagerConfirm" Align="Center" Format="dd-MM-yyyy" />
                <ext:DateColumn Header="Ngày hoàn thành" DataIndex="DateFinished" Align="Center" Format="dd-MM-yyyy"/>
                
                <ext:Column Header="Độ ưu tiên" DataIndex="Priority" Align="Center" Groupable="true">
                    <Renderer Fn="priorityFn" />
                </ext:Column>
                <ext:Column Header="NV đang làm" DataIndex="UsersRepair" />
                <%--<ext:Column Header="File đính kèm" DataIndex="ErrorReport_FilePath">
                    <Renderer Fn="LoadAttachs" />
                </ext:Column>--%>
                <%--<ext:Column Header="Đã xóa" DataIndex="IsDeleted" Align="Center" Groupable="true">
                    <Renderer Handler="return (value) ? 'Ðã xóa':'Chưa xóa';" />
                </ext:Column>--%>
            </Columns>
        </ColumnModel>
        <Listeners>
            <Command Handler="Ext.net.DirectMethods.LoadNotes(command,record.data.NoteGroupId,record.data.ErrorID);" />
        </Listeners>
        <SelectionModel>
            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1"  runat="Server">
            </ext:CheckboxSelectionModel>
        </SelectionModel>
        <View>
            <ext:GroupingView ID="GroupingView1" runat="server" ForceFit="true" MarkDirty="false"
                ShowGroupName="true" EnableNoGroups="true" HideGroupedColumn="true" ShowGroupsText="Nhóm lại theo cột này" />
        </View>
        <LoadMask ShowMask="true" />
        <Plugins>
            <ext:GridFilters runat="server" ID="GridFilters1">
                <Filters>
                    <ext:NumericFilter DataIndex="WorkWarrantyID" />
                    <ext:NumericFilter DataIndex="Priority" />
                    <ext:DateFilter DataIndex="DateReport">
                        <DatePickerOptions runat="server" TodayText="Now" />
                    </ext:DateFilter>
                    <ext:DateFilter DataIndex="DateFinished">
                        <DatePickerOptions runat="server" TodayText="Now" />
                    </ext:DateFilter>
                    
                </Filters>
            </ext:GridFilters>
            <ext:RowExpander ID="RowExpander1" runat="Server">
                <Template ID="Template1" runat="Server">
                    <Html>
                        <div style="padding: 10px; line-height: 1.5em">
                            
							<p><b>Tên lỗi       : </b> {ErrorReport_ErrorName}</p>
                            <p><b>Thông tin     : </b>{ErrorReport_DesOfCustomer}</p>
                            
							<p><b>Đoán lỗi của quản lý : </b></p>
                            
                            <p>{DescOfManager}</p>
                            
                            <p><b>Đoán lỗi của nhân viên :</b></p>
                            
                            <p>{DescOfEmployee}</p>
							
                        </div>
                    </Html>
                </Template>
            </ext:RowExpander>
        </Plugins>
        <BottomBar>
            <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" />
        </BottomBar>
    </ext:GridPanel>
 
    <uc:WorkAddEdit ID="workAddEdit1" runat="Server" ReloadGrid="GridPanel1"  />
 

    <ext:Window ID="Window4" runat="Server" Constrain="true" Icon="ApplicationEdit" Title="Trạng thái công việc"
        Width="500" Height="200"  Hidden="true" ButtonAlign="Center" AutoDataBind="false">
        <Items>
            
            <ext:Panel ID="Panel2" runat="Server" ButtonAlign="Center" Layout="FormLayout" LabelWidth="50" Width="500">

                <Items>
                    <ext:Label ID="Label1" runat="Server" Text="Chọn trạng thái công việc" />
                   
                    <ext:ComboBox ID="cbxState" runat="Server" Width="300" SelectedIndex="0" >
                        <Items>
                            <ext:ListItem Text="Đã khởi tạo " Value="1" />
                            <ext:ListItem Text="Đã phân công" Value="2" />
                            <ext:ListItem Text="Đã thực hiên" Value="3" />
                            <ext:ListItem Text="Nhân viên xác nhận xong" Value="4" />
                            <ext:ListItem Text="Khách hàng xác nhận xong" Value="5" />
                            <ext:ListItem Text="Quản lý xác nhận xong, hoàn tất" Value="6" />
                        </Items>
                    </ext:ComboBox>
                </Items>
                <Buttons>
                    <ext:Button runat="server" ID="btnSetState" Text="Cập nhật">
                        <DirectEvents>
                            <Click OnEvent="btnSetState_Click" />
                        </DirectEvents>
                    </ext:Button>
                    <ext:Button ID="Button1" runat="Server" Text="Bỏ qua">
                        <Listeners>
                            <Click Handler="#{Window3}.hide();" />
                        </Listeners>
                    </ext:Button>
                </Buttons>
            </ext:Panel>
        </Items>
        </ext:Window>

    <ext:Window ID="wWorkNote" runat="Server" Collapsible="true" Icon="Pencil" Title="Notes"
        Width="960" Height="500" AutoScroll="true" Hidden="true" ButtonAlign="Center" AutoDataBind="false" Modal="true" Maximizable="true">
        <AutoLoad ShowMask="true" Mode="IFrame"/>    
    </ext:Window>



    <ext:Window ID="wProductDetail" runat="Server"  Title="Chi tiết sản phẩm lỗi "
        Collapsible="true" Icon="ApplicationViewDetail" Width="900" Height="500" AutoScroll="true"
        Hidden="true" ButtonAlign="Center" AutoDataBind="false" Modal="true" Maximizable="true">

        <AutoLoad ShowMask="true" Mode="IFrame" />
    </ext:Window>
</asp:Content>
